from supervisely.app import DataJson
from supervisely.app.widgets import Widget
from supervisely.annotation.obj_class import ObjClass


from supervisely.geometry.bitmap import Bitmap
from supervisely.geometry.alpha_mask import AlphaMask
from supervisely.geometry.cuboid import Cuboid
from supervisely.geometry.point import Point
from supervisely.geometry.polygon import Polygon
from supervisely.geometry.polyline import Polyline
from supervisely.geometry.rectangle import Rectangle
from supervisely.geometry.graph import GraphNodes
from supervisely.geometry.any_geometry import AnyGeometry
from supervisely.geometry.cuboid_3d import Cuboid3d
from supervisely.geometry.pointcloud import Pointcloud
from supervisely.geometry.point_3d import Point3d
from supervisely.geometry.multichannel_bitmap import MultichannelBitmap
from supervisely.geometry.closed_surface_mesh import ClosedSurfaceMesh


type_to_zmdi_icon = {
    AnyGeometry: "zmdi zmdi-shape",
    Rectangle: "zmdi zmdi-crop-din",  # "zmdi zmdi-square-o"
    # Polygon: "icons8-polygon",  # "zmdi zmdi-edit"
    Bitmap: "zmdi zmdi-brush",
    AlphaMask: "zmdi zmdi-brush",
    Polyline: "zmdi zmdi-gesture",
    Point: "zmdi zmdi-dot-circle-alt",
    Cuboid: "zmdi zmdi-ungroup",  #
    # Cuboid3d: "zmdi zmdi-codepen",
    Pointcloud: "zmdi zmdi-cloud-outline",  #  # "zmdi zmdi-border-clear"
    MultichannelBitmap: "zmdi zmdi-layers",  # "zmdi zmdi-collection-item"
    Point3d: "zmdi zmdi-filter-center-focus",  # "zmdi zmdi-select-all"
}

type_to_icons8_icon = {
    Polygon: "",
    # Polyline: "",
    # Cuboid: "",
    GraphNodes: "",
    Cuboid3d: "",  # "zmdi zmdi-codepen"
    # ClosedSurfaceMesh: "",
    # ClosedSurfaceMesh: "",
    ClosedSurfaceMesh: "",
    # Point3d: "",
}

type_to_shape_text = {
    AnyGeometry: "any shape",
    Rectangle: "rectangle",
    Polygon: "polygon",
    Bitmap: "bitmap (mask)",
    AlphaMask: "alpha mask",
    Polyline: "polyline",
    Point: "point",
    Cuboid: "cuboid",  #
    Cuboid3d: "cuboid 3d",
    Pointcloud: "pointcloud",  #  # "zmdi zmdi-border-clear"
    MultichannelBitmap: "n-channel mask",  # "zmdi zmdi-collection-item"
    Point3d: "point 3d",  # "zmdi zmdi-select-all"
    GraphNodes: "keypoints",
    ClosedSurfaceMesh: "volume (3d mask)",
}


class ObjectClassView(Widget):
    def __init__(
        self,
        obj_class: ObjClass,
        show_shape_text: bool = True,
        show_shape_icon: bool = False,
        widget_id: str = None,
    ):
        self._obj_class = obj_class
        self._show_shape_text = show_shape_text
        self._show_shape_icon = show_shape_icon
        super().__init__(widget_id=widget_id, file_path=__file__)

    def get_json_data(self):
        res = self._obj_class.to_json()
        res["icon"] = None
        res["icon8"] = None
        if self._show_shape_icon is True:
            res["icon"] = type_to_zmdi_icon.get(self._obj_class.geometry_type)
            res["icon8"] = type_to_icons8_icon.get(self._obj_class.geometry_type)
        res["shape_text"] = None
        if self._show_shape_text is True:
            res["shape_text"] = type_to_shape_text.get(
                self._obj_class.geometry_type
            ).upper()
        return res

    def get_json_state(self):
        return None
